#include "register.h"
#include "ui_register.h"

#include <QPushButton>
#include <QString>
#include <jsoncpp/json/json.h>

#include "Logger.hpp"
#include "usermanagement.h"

Register::Register(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Register)
{
    ui->setupUi(this);

    connect(ui->register_btn, &QPushButton::clicked, this, &Register::register_btn_clicked);
}

Register::~Register()
{
    delete ui;
}

void Register::register_btn_clicked()
{
    QString username = ui->name_ld->text();
    QString passwd = ui->passwd_ld->text();
    QString identity = ui->doctor_rbtn->isChecked() ? "doctor" : "patient";


    int age = ui->age_ld->text().isEmpty() ? -1 : ui->age_ld->text().toInt();
    QString gender = ui->gender_ld->text().isEmpty() ? "" : ui->gender_ld->text();
    QString phone = ui->phone_ld->text().isEmpty() ? "" : ui->phone_ld->text();
    QString address = ui->address_ld->text().isEmpty() ? "" : ui->address_ld->text();

    if(username.isEmpty() || passwd.isEmpty() || identity.isEmpty()) {
        LOG_INFO() << "必要信息未填写";
    }

    Json::Value userInfo;
    userInfo["username"] = username.toStdString();
    userInfo["password"] = passwd.toStdString();
    userInfo["identity"] = identity.toStdString();
    userInfo["age"] = age;
    userInfo["gender"] = gender.toStdString();
    userInfo["phone"] = phone.toStdString();
    userInfo["address"] = address.toStdString();

    if()
}
